local jieming = fk.CreateSkill {
  name = "lvshi__jieming",
}
Fk:loadTranslationTable {
  ["lvshi__jieming"] = "节命",
  [":lvshi__jieming"] = "当你受到1点伤害后，你可令一名角色将手牌调整至四张。",
  ["#lvshi__jieming-choose"] = "节命：你可令一名角色将手牌调整至四张",

  ["$lvshi__jieming1"] = "三尺之躯，亦可死节也！",
  ["$lvshi__jieming2"] = "襄曹而秉汉，守节而立命。",
}

jieming:addEffect(fk.Damaged, {
  anim_type = "masochism",
  trigger_times = function(self, event, target, player, data)
    return data.damage
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room.alive_players,
      skill_name = jieming.name,
      prompt = "#lvshi__jieming-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    local num = 4 - to:getHandcardNum()
    if num > 0 then
      to:drawCards(num, jieming.name)
    elseif num < 0 then
      num = math.abs(num)
      player.room:askToDiscard(to, {
        skill_name = jieming.name,
        cancelable = false,
        min_num = num,
        max_num = num,
        include_equip = false,
      })
    end
  end,
})

return jieming